package cbfg.butil.demo

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import cbfg.butil.ToastUtils
import cbfg.butil.demo.databinding.FragmentToastBinding

/**
 * @author:  Tom Hawk
 * 添加时间: 2020/9/3 15:07
 * 功能描述:
 */
class ToastFragment : Fragment(R.layout.fragment_toast), View.OnClickListener {
    private var _binding: FragmentToastBinding? = null
    private val binding: FragmentToastBinding
        get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = super.onCreateView(inflater, container, savedInstanceState)!!
        _binding = FragmentToastBinding.bind(view)
        return view
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.btnShowShort.setOnClickListener(this)
        binding.btnShowShortRes.setOnClickListener(this)
        binding.btnShowLong.setOnClickListener(this)
        binding.btnShowLongRes.setOnClickListener(this)
        binding.btnDebugShowShort.setOnClickListener(this)
        binding.btnDebugShowLong.setOnClickListener(this)
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.btnShowShort -> ToastUtils.showShort("ShowShort,${System.currentTimeMillis()}")
            R.id.btnShowShortRes -> ToastUtils.showShort(R.string.app_name)
            R.id.btnShowLong -> ToastUtils.showLong("ShowLong,${System.currentTimeMillis()}")
            R.id.btnShowLongRes -> ToastUtils.showLong(R.string.app_name)
            R.id.btnDebugShowShort -> ToastUtils.debugShowShort("DebugShowShort,${System.currentTimeMillis()}")
            R.id.btnDebugShowLong -> ToastUtils.debugShowLong("DebugShowLong,${System.currentTimeMillis()}")
        }
    }

}